package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the totalPower method with various inputs for correct outputs.
 * 
 * @author Alex Kan and Kelvin Green
 * @version 2.0
 */
public class TestWattDepotTotalPower {

  WattDepotCommand commandInstance;
  String[] commandArray;
  String userInput;

  /**
   * Test for WattDepotTotalPower command for 2 correct outputs and errors on 2 inputs.
   * 
   * Test (correct) totalpower SIM_WAIAU 2009-11-15T12:13:00.000-10:00 fuelType LSFO: 176 Test
   * (correct) totalpower SIM_IPP 2009-10-26T15:00:00.000-10:00 fuelType waste: 46 Test (error)
   * totalpower SIM_WAIAU 2009-11-15T12:13:00.000-10:00 fuelType: totalpower {source} {timestamp}
   * fuelType {fuelType} Test (error) totalpower SIM_WAIAU 2009-11-1512:13:00.000-10:00 fuelType
   * LSFO: Not a valid timestamp.
   */
  @Test
  public void testTotalPower() {
    WattDepotCommand.connect("http://server.wattdepot.org:8182/wattdepot/");
    commandInstance = new WattDepotTotalPowerCommand();
    userInput = "totalpower SIM_WAIAU 2009-11-15T12:13:00.000-10:00 fuelType LSFO";
    commandArray = userInput.split(" ");
    assertTrue("Check for total power", commandInstance.doCommand(commandArray).contains("176"));

    commandInstance = new WattDepotTotalPowerCommand();
    userInput = "totalpower SIM_IPP 2009-10-26T15:00:00.000-10:00 fuelType waste";
    commandArray = userInput.split(" ");
    assertTrue("Check for total power", commandInstance.doCommand(commandArray).contains("46"));

    commandInstance = new WattDepotTotalPowerCommand();
    userInput = "totalpower SIM_WAIAU 2009-11-15T12:13:00.000-10:00 fuelType";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "totalpower {source} {timestamp} fuelType {fuelType}"));

    commandInstance = new WattDepotTotalPowerCommand();
    userInput = "totalpower SIM_WAIAU 2009-11-1512:13:00.000-10:00 fuelType LSFO";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "Not a valid timestamp."));
  }
}
